/**
 * 
 */
package com.${ltdAbbr}.xiao.${module}.bo.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ConsumerConfig;
import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.ProviderConfig;
import com.alibaba.dubbo.config.RegistryConfig;

/**
 * @author admin
 *
 */
@Configuration
public class DubboConfiguration {

    <#noparse>@Value("${dubbo.register.address}")</#noparse>
    private String dubboRegisterAddress;

    /**
     * 定义dubbo ApplicationConfig
     * @return
     */
    @Bean("dubboApplicationConfig")
    public ApplicationConfig createApplicationConfig() {
        ApplicationConfig applicationConfig = new ApplicationConfig();
        applicationConfig.setName("${ltdAbbr}-${module}-service");
        return applicationConfig;
    }

    /**
     * 定义dubbo ProtocolConfig
     * @return
     */
    @Bean("dubboProtocolConfig")
    public ProtocolConfig createProtocolConfig() {
        ProtocolConfig protocolConfig = new ProtocolConfig();
        protocolConfig.setName("dubbo");
        protocolConfig.setPort(60021);
        protocolConfig.setThreadpool("fixed");
        protocolConfig.setThreads(500);
        return protocolConfig;
    }

    /**
     * 定义dubbo RegistryConfig
     * @return
     */
    @Bean("dubboRegistryConfig")
    public RegistryConfig createRegistryConfig() {
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setAddress(dubboRegisterAddress);//zookeeper://127.0.0.1:2181
        //registryConfig.setClient("netty");
        //registryConfig.setPort(60021);
        registryConfig.setProtocol("zookeeper");
        //registryConfig.setFile(file);
        return registryConfig;
    }

    /**
     * 定义dubbo ProviderConfig
     * @return
     */
    @Bean("dubboProviderConfig")
    public ProviderConfig createProviderConfig() {
        ProviderConfig providerConfig = new ProviderConfig();
        providerConfig.setRetries(1);
        providerConfig.setTimeout(10000);
        providerConfig.setFilter("-exception,exceptionFilter");
        providerConfig.setConnections(10);
        providerConfig.setVersion("1.0.0");
        return providerConfig;
    }

    /**
     * 定义dubbo ConsumerConfig
     * @return
     */
    @Bean("dubboConsumerConfig")
    public ConsumerConfig createConsumerConfig() {
        ConsumerConfig consumerConfig = new ConsumerConfig();
        //consumerConfig.setRetries(1);
        //consumerConfig.setTimeout(10000);
        consumerConfig.setFilter("-exception,exceptionFilter");
        //consumerConfig.setConnections(10);
        consumerConfig.setVersion("1.0.0");
        consumerConfig.setCheck(false);
        return consumerConfig;
    }
}
